<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<script>
//使用ajax来判断旧密码与数据库中的密码是否一致
$(function(){
	//先写一个鼠标移开的事件
	$('#spassword').blur(function(){
		var spassword = $('#spassword').val();//获取文本框的值
		var newpassword = $('#newpassword').val();//获取文本框的值
		//部分路径
			$.ajax({
				type : "post",//post的提交方式
				url : "userLoginServlet.do",//完整的路径
				async : false,
				data : {//获取旧的密码和跳转到servlet文件的方法名
					"newPassword" : newpassword,
					"oldPassword" : spassword,
					"method" : "updatePassword"
				},
				success : function(data) {//成功的话判断密码是否为数据库中的密码
					if (data == "true") {//如果为true则输入正确
						$('#"spassword2"').text('输入正确');
					} else {//判断是否为空
						if (oldpwd == "" || oldpwd == null) {
							$('#"spassword2"').text('旧密码不能为空');
						} else {
							$('#"spassword2"').text('密码输入不正确');
						}
					}
				},
				error : function() {
					alert("失败");
				}
			});
		})
	})
</script>

</head>
<body>
<form id="dept-add-dlg-form" action="userLoginServlet.do?method=updatePassword"
		method="post">
		 <input type="hidden" name="id">
		<div class="datagrid-body">
			<table class="datagrid-btable" cellspacing="0" cellpadding="0"
				border="0" style="width: 100%;">
				<tbody>
		
					<tr class="datagrid-row">
						<td
							style="border-style: solid; width: 15%; text-align: right; padding-right: 7px">原密码</td>
						<td style="border-style: solid; width: 35%; text-align: left;">
							<input type="password" name="oldPassword" id="oldPassword" required="true" placeholder="请填写当前密码"
							class="easyui-validatebox" style="width: 266px">
							<span id="spassword2"></span>
						</td>
					</tr>
					

					<tr class="datagrid-row">
						<td
							style="border-style: solid; width: 15%; text-align: right; padding-right: 7px">新密码</td>
						<td style="border-style: solid; width: 35%; text-align: left;">
							<input type="password" id="newPassword" name="newPassword" required="true" value="" validType="length[4,8]"
							class="easyui-validatebox" style="width: 266px">
						</td>
					</tr>
					<tr class="datagrid-row">
						<td
							style="border-style: solid; width: 15%; text-align: right; padding-right: 7px">确认密码</td>
						<td style="border-style: solid; width: 35%; text-align: left;">
							<input type="password" id="newtopassword" name="newtopassword" required="true"
							class="easyui-validatebox" validType="equalTo['#newpassword']" invalidMessage="输入密码不匹配" style="width: 266px">
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	</form>
<script type="text/javascript">
function getQueryParam(name) {
     var obj = $('#common-dialog').dialog('options');
     var queryParams = obj["queryParams"];
     return queryParams[name];
}
//自动填充值
function autoInput(obj){
 	$.each(obj, function(i, n){
	  //from 下的input
	  $("#dept-add-dlg-form input[name='"+i+"']").val(n);
	});
}
$(function(){
	var _id  =getQueryParam("id");
	$.getJSON("UserServlet?method=edit",{id:_id},function(json){
			//自动添值
		  autoInput(json);
	});
});
</script>
</body>
</html>